package com.example.sjjg.utest

import androidx.lifecycle.Lifecycle
import androidx.test.core.app.ActivityScenario
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.example.sjjg.utest.view.MainActivity
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.Robolectric
import org.robolectric.RobolectricTestRunner


@RunWith(RobolectricTestRunner::class)
class RobolectricActivity {

    @Test
    fun setupActivity(){
        Robolectric.setupActivity(MainActivity::class.java)
    }

    @Test
    fun test_activity_lifecycle(){

        // GIVEN
        val controller = Robolectric.buildActivity(MainActivity::class.java).setup()
        val activity = controller.get()

        // WHEN
        controller.pause().stop()

        // THEN
        println("value = $activity.lifeCycle")
        assertTrue(activity.lifeCycle == 5)
    }
}
@RunWith(AndroidJUnit4::class)
class AndroidXActivity{

    @Test
    fun test_activity_lifecycle(){
        // GIVEN
        val scenario = ActivityScenario.launch(MainActivity::class.java)

        // WHEN
        scenario.moveToState(Lifecycle.State.CREATED)

        // THEN
        scenario.onActivity { activity ->
            assertTrue(activity.lifeCycle  == 0)
        }
    }
}